#include "LayerViewerWidget.hpp"
#include <qpainter.h>
#include <GL/gl.h>
#include <GL/glu.h>

    LayerViewerWidget::LayerViewerWidget( ImageAnalysis::Layer* layer)
    : QGLWidget(), currentLayer(layer)
    {

    }

    LayerViewerWidget::~LayerViewerWidget()
    {

    }

    void LayerViewerWidget::initializeGL()
    {
        resize( currentLayer->GetWidth(), currentLayer->GetHeight() );

        glClearColor( 0.0, 0.0, 0.0, 0.0 );

    }

    void LayerViewerWidget::resizeGL( int width, int height )
    {
        glViewport(0,0,width,height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0,width,0,height);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }

    void LayerViewerWidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glPixelStorei(GL_UNPACK_ALIGNMENT,1);
        currentLayer->Draw();
        glRasterPos2i(0,0);
        glFlush();

    }
